<!DOCTYPE HTML>
<html>
<head>
    <include file="Public/head" />
<title>计划入库单详情</title>
</head>
<body>
<div class="pd-20">

	<table class="table table-border table-bordered table-bg">

		<tbody>
			<tr class="text-c">
				<td width="" class="text-r" style="background-color:#f5f5f5">采购单编号</td>
				<td class="text-l">
					{$detail.purchasing_no}
				</td>
				<td width="" class="text-r" style="background-color:#f5f5f5">申请部门</td>
				<td class="text-l">
					{$detail.section}
				</td>
			</tr>
			<tr class="text-c">
				<td width="" class="text-r" style="background-color:#f5f5f5">产品数量</td>
				<td class="text-l">
					<input type="text"  class="input-text"  style="width:80px" name="pro_num" value="{$detail.pro_num}" >
				</td>
				<td width="" class="text-r" style="background-color:#f5f5f5">产品名称</td>
				<td class="text-l">
					{$detail.pro_name}
				</td>	
			</tr>
			<tr class="text-c">
				<td class="text-r" style="background-color:#f5f5f5">料号</td>
				<td class="text-l">
					{$detail.source_no}
				</td>
				<td class="text-r" style="background-color:#f5f5f5">产品编码</td>
				<td class="text-l">
					{$detail.pro_no}
				</td>				
			</tr>
			<tr class="text-c">
				<td width="" class="text-r" style="background-color:#f5f5f5">商品入库成本单价</td>
				<td class="text-l inbound_price">
					{$inbound_price}
				</td>
				<td width="" class="text-r" style="background-color:#f5f5f5">原料生产价</td>
				<td class="text-l material_cost_price">
					{$material_cost_price}
				</td>
			</tr>
			<tr class="text-c">
				<td width="" class="text-r" style="background-color:#f5f5f5">产品销售成本价</td>
				<td class="text-l">
					{$detail.sell_price}
				</td>
				<td width="" class="text-r" style="background-color:#f5f5f5">出厂价</td>
				<td class="text-l">
					{$detail.factory_price}
				</td>
			</tr>
			<tr class="text-c">
				<td width="" class="text-r" style="background-color:#f5f5f5">规格(g)</td>
				<td class="text-l">
					{$detail.pro_spec}
				</td>
				<td width="" class="text-r" style="background-color:#f5f5f5"></td>
				<td class="text-l">
					
				</td>
			</tr>
		</tbody>
	</table>
	
	<table class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="16">原料列表</th>
			</tr>
			<tr class="text-c">
				<th width="40">ID</th>
				<th width="40">生产计划单编号</th>
				<th width="40">料号</th>
				<th width="40">项号</th>
				<th width="40">料件性质</th>
				<th width="40">商品编码</th>
				<th width="40">商品名称</th>
				<th width="40">币制</th>
				<th width="40">原料采购单价</th>
				
				<th width="40">损耗单价</th>
				<th width="40">损耗重量(kg)</th>
				<th width="40">边角料单价</th>
				<th width="40">边角料重量(kg)</th>
				<th width="40">数量(包)</th>
				<th width="40">规格(g)</th>
				<th width="40">原产国</th>
			</tr>
		</thead>
		<tbody>
			<volist name="list" id="vo">
			<tr class="text-c">
			 <input  name='gid' type="hidden" style="width:80px;" value="{$vo['id']}"/>
				<td>{$vo.id}</td>
				<td><span>{$vo.plan_receipts_id}</span></td>
				<td>{$vo.source_no}</td>
				<td>{$vo.item_no}</td>
				<td>{$vo.item_type}</td>
				<td>{$vo.goods_no}</td>
				<td>{$vo.goods_name.goods_name}</td>
				<td>{$vo.currency_name}</td>
				<td>
					{$vo['price']}
				</td>
				
				<td>
					<input  name='material_price' type="hidden" style="width:80px" value="{$vo['material_price']>0?$vo['material_price']:$vo['list_price']['material_price']}"/>
					{$vo['material_price']>0?$vo['material_price']:$vo['list_price']['material_price']}
				</td>
				<td>
					<input  name='material_weight' type="input-text" style="width:80px" value="{$vo['material_weight']}"/>
				</td>
				<td>
					<input  name='scrap_price' type="hidden" style="width:80px" value="{$vo['scrap_price']>0?$vo['scrap_price']:$vo['list_price']['scrap_price']}"/>
					{$vo['scrap_price']>0?$vo['scrap_price']:$vo['list_price']['scrap_price']}
					
				</td>
				<td>
					<input  name='scrap_weight' type="input-text" style="width:80px" value="{$vo['scrap_weight']}"/>
				</td>
				<td>
					{$vo['declare_amount']}
				</td>
				<td>
					{$vo['goods_spec']}
				</td>
				<td>

                         <volist name="country" id="vcc">
							 <if condition="$vcc['country_code'] == $vo['country_code']">
								{$vcc.country_name}
							</if>
                         </volist>

				</td>
	
			</tr>
			</volist>
		</tbody>
	</table>

	<button href="javascript:;" id="edit" class="btn btn-primary radius mt">保存修改</button>
	<!-- <button class="btn btn-primary mt" id="inbound_price">计算商品入库成本价</button>
	<button class="btn btn-primary mt" id="material_cost_price">计算原料生产价</button> -->
	<br>
	注：保存修改数据后查看价格<br>
		
		商品入库成本单价：（原料采购单价-损耗单价*损耗重量-边角料单价*边角料重量）/数量<br>
		产品销售成本价：自定义<br>
		原料成本价：默认等于原料采购成本单价之和。<br>
		出厂价：自定义<br>
	
<div class="pages">
{$page}
</div>
</div>
<script type="text/javascript">
    $(function(){
		/*计算入库成本价*/
		$("#inbound_price").click(function(){
			$.ajax({
                type: 'POST',
                data: {
						id:{:I('id')}
					  },
                url: "{:U('count_inbound')}",
                success:function(data){
					if(data.status){
						 layer.msg('计算成功');
						 $('.inbound_price').text(data.inbound_price);
					}else{
						 layer.msg(data.info);
					}
                   
                }
            })
		
		
		})
		/*计算原料生产价*/
		$("#material_cost_price").click(function(){
			$.ajax({
                type: 'POST',
                data: {
						id:{:I('id')}
					  },
                url: "{:U('count_material')}",
                success:function(data){
					if(data.status){
						 layer.msg('计算成功');
						 $('.material_cost_price').text(data.inbound_price);
					}else{
						 layer.msg(data.info);
					}
                   
                }
            })
		
		
		})
		/*保存计划入库单数据*/
        $("#edit").click(function(){
			var material_price=$('input[name=material_price]');
			var material_weight=$('input[name=material_weight]');
			var scrap_price=$('input[name=scrap_price]');
			var scrap_weight=$('input[name=scrap_weight]');
			
			var pro_num=$('input[name=pro_num]').val();
				
				if(pro_num==''){
					layer.msg('产品数量不能为空');
					return false;
				}
				if(pro_num=='0'){
					layer.msg('产品数量不能为0');
					return false;
				}
				
			var count=$('input[name=material_weight]').length;
			var gid=$('input[name=gid]');
			if(count<1){
				layer.msg('没有添加原料');
				return false;
			}
			var str='';
			for(var i=0;i<count;i++){

				if(material_weight.eq(i).val()==0){
					layer.msg('损耗重量不能为0');
					return false;
				}

				if(scrap_weight.eq(i).val()==0){
					layer.msg('边角料重量不能为0');
					return false;
				}

				
				if(i==0){
					str=str+gid.eq(i).val()+":"+material_price.eq(i).val()+":"+material_weight.eq(i).val()+":"+scrap_price.eq(i).val()+":"+scrap_weight.eq(i).val();
				}else{
					str=str+","+gid.eq(i).val()+":"+material_price.eq(i).val()+":"+material_weight.eq(i).val()+":"+scrap_price.eq(i).val()+":"+scrap_weight.eq(i).val();
				}
			}
			
			$.ajax({
                type: 'POST',
                data: {
						id:{:I('id')},
						pro_num:pro_num,
						strss:str
					  },
                url: "{:U('edit_procost_detail')}",
                success:function(data){
                    layer.msg(data.info,function(){
						if(data.status==0){
							return false;
						}else{
							self.window.location.href =self.window.location.href;
						}
						
					});
                }
            })
            
        });
		



    })
</script>
</body>
</html>